package tech.waterism.utils;



import tech.waterism.entity.FCurveHq;

import java.util.List;

public class ConvertZQ {
    /**
     * 已知水位，用两点插值求流量
     *
     * @return 流量
     * @parameter double q
     */
    public static double getQFromZ(List<FCurveHq> curveHq, double z) {
        double q;
        q = MathFun.insert2(z,
                curveHq.stream().mapToDouble(FCurveHq::getZ).toArray(),
                curveHq.stream().mapToDouble(FCurveHq::getQ).toArray(),
                curveHq.size());
        return q;
    }

    /**
     * 已知流量，用两点插值求水位
     *
     * @return 水位
     * @parameter double q
     */
    public static double getZFromQ(List<FCurveHq> curveHq, double q) {
        double z;
        z = MathFun.insert2(q
                , curveHq.stream().mapToDouble(FCurveHq::getQ).toArray()
                , curveHq.stream().mapToDouble(FCurveHq::getZ).toArray()
                , curveHq.size());
        return z;
    }
}
